#include <Keyboard.h>
#include <Mouse.h>

char inByte = 0; 
uint32_t nowtime;
uint32_t duration=10000;//设定时间    1分钟=（60000毫秒）
int state=1;       //0表示TRUE，1表示FALSE

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Keyboard.begin();
//  Mouse.begin();
  Keyboard.releaseAll();    //向电脑发送按键释放的指令   
}

void loop() {
  if (Serial.available() > 0) 
  {
    inByte = Serial.read();
    // put your main code here, to run repeatedly:
    if(inByte != 0 ){
      Keyboard.press(inByte);   // 向电脑发送向左按键按下的指令 
      nowtime = millis();
      state = 0;
    }else{
      Keyboard.releaseAll();    // 向电脑发送按键释放的指令   
      state = 1;
    }       
    delay(20);
  }
  if(millis() - nowtime > duration && state == 0)
  {
    Keyboard.releaseAll();    //向电脑发送按键释放的指令   
    nowtime = millis();
    state == 1;
  }
}
